package com.example.terminal.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.terminal.R;
import com.example.terminal.base.BaseRecyclerAdapter;
import com.example.terminal.base.BaseViewHolder;
import com.example.terminal.bean.StocktakingDetailsBean;
import com.example.terminal.bean.StocktakingListBean;

import java.util.List;

public class StocktakingScanAdapter extends BaseRecyclerAdapter<StocktakingDetailsBean.DataBean.TcheckDeviceListBean.DeviceDetailListBean> {

    private String mCheckFlagName;
    private String mImeiStatus;

    public StocktakingScanAdapter(Context mContext, List<StocktakingDetailsBean.DataBean.TcheckDeviceListBean.DeviceDetailListBean> mList, String checkFlagName, String imeiStatus) {
        super(mContext, mList);
        this.mCheckFlagName = checkFlagName;
        this.mImeiStatus = imeiStatus;
    }

    @Override
    public int setContentView() {
        return R.layout.adapter_scan_stocktaking;
    }

    @Override
    protected void bindData(BaseViewHolder holder, StocktakingDetailsBean.DataBean.TcheckDeviceListBean.DeviceDetailListBean data, int position) {
        TextView mTv_position = holder.findViewById(R.id.mTv_position);
        TextView mTv_positionlist = holder.findViewById(R.id.mTv_positionlist);
        TextView mTv_describe = holder.findViewById(R.id.mTv_describe);
        RelativeLayout mRl_describe = holder.findViewById(R.id.mRl_describe);
        TextView mTv_state = holder.findViewById(R.id.mTv_state);
        RelativeLayout mRl_state = holder.findViewById(R.id.mRl_state);
        ImageView mIv_ImgState = holder.findViewById(R.id.mIv_ImgState);
        RelativeLayout mRl_ImgState = holder.findViewById(R.id.mRl_ImgState);

        if (mCheckFlagName.equals("通过")) {
            mRl_state.setVisibility(View.GONE);
            mRl_ImgState.setVisibility(View.GONE);
        }

        if (mImeiStatus.equals("1")) {
            mTv_positionlist.setText(data.getImei());
        } else {
            mTv_positionlist.setText(data.getNum() + "");
        }

        boolean coken = data.isCoken();
        int ackFlag = data.getAckFlag();
        if (ackFlag == 0) {
            mIv_ImgState.setBackground(mContext.getDrawable(R.mipmap.complete_no_log));
        } else {
            mIv_ImgState.setBackground(mContext.getDrawable(R.mipmap.complete_log));
        }
//        if (coken) {
//            mIv_ImgState.setBackground(mContext.getDrawable(R.mipmap.complete_log));
//        } else {
//            mIv_ImgState.setBackground(mContext.getDrawable(R.mipmap.complete_no_log));
//        }


        mTv_position.setText(position + 1 + "");

        mTv_state.setText(data.getErrorStatus());
        mTv_describe.setText(data.getRemark());

        setOnTextClickListener(mIv_ImgState, position);
        setOnTextClickListener(mRl_describe, position);

    }
}
